namespace QMVnSoft.ReportForms
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDMVT02Viewer : FormReportViewer
    {
        private IContainer components;
        private LabelControl lblCopies;
        private LabelControl lblMa_Nh_Vt;
        private TextNumeric txtCopies;
        private TextSearch txtMa_Nh_Vt;
        private TextControl txtTen_Nh_Vt;

        public FormDMVT02Viewer()
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private DataTable GetSelectedRows()
        {
            DataTable table = new DataTable();
            DataColumn column = new DataColumn("Ma_Vt", typeof(string));
            table.Columns.Add(column);
            column = new DataColumn("Ten_Vt", typeof(string));
            table.Columns.Add(column);
            column = new DataColumn("Gia_Ban", typeof(decimal));
            table.Columns.Add(column);
            if ((base.DataGridBrowser.SelectedRows.Count != 0) || (base.LocalTable.Rows.Count != 0))
            {
                DataRow row;
                if (base.DataGridBrowser.SelectedRows.Count != 0)
                {
                    foreach (DataGridViewRow row2 in base.DataGridBrowser.SelectedRows)
                    {
                        for (int j = 0; j < this.txtCopies.NumericValue; j++)
                        {
                            row = table.NewRow();
                            row["Ma_Vt"] = ((DataRowView) row2.DataBoundItem).Row["Ma_Vt"];
                            row["Ten_Vt"] = ((DataRowView) row2.DataBoundItem).Row["Ten_Vt"];
                            row["Gia_Ban"] = ((DataRowView) row2.DataBoundItem).Row["Gia_Ban"];
                            table.Rows.Add(row);
                        }
                    }
                    return table;
                }
                for (int i = 0; i < this.txtCopies.NumericValue; i++)
                {
                    row = table.NewRow();
                    row["Ma_Vt"] = ((DataRowView) base.DataGridBrowser.CurrentRow.DataBoundItem).Row["Ma_Vt"];
                    row["Ten_Vt"] = ((DataRowView) base.DataGridBrowser.CurrentRow.DataBoundItem).Row["Ten_Vt"];
                    row["Gia_Ban"] = ((DataRowView) base.DataGridBrowser.CurrentRow.DataBoundItem).Row["Gia_Ban"];
                    table.Rows.Add(row);
                }
            }
            return table;
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormDMVT02Viewer));
            this.txtTen_Nh_Vt = new QMVnSoft.Controls.TextControl();
            this.txtMa_Nh_Vt = new QMVnSoft.Controls.TextSearch();
            this.lblMa_Nh_Vt = new QMVnSoft.Controls.LabelControl();
            this.txtCopies = new QMVnSoft.Controls.TextNumeric();
            this.lblCopies = new QMVnSoft.Controls.LabelControl();
            this.rptContainer.Panel1.SuspendLayout();
            this.rptContainer.SuspendLayout();
            this.SuspendLayout();
            // 
            // rptContainer
            // 
            // 
            // rptContainer.Panel1
            // 
            this.rptContainer.Panel1.Controls.Add(this.txtCopies);
            this.rptContainer.Panel1.Controls.Add(this.txtTen_Nh_Vt);
            this.rptContainer.Panel1.Controls.Add(this.txtMa_Nh_Vt);
            this.rptContainer.Panel1.Controls.Add(this.lblCopies);
            this.rptContainer.Panel1.Controls.Add(this.lblMa_Nh_Vt);
            this.rptContainer.SplitterDistance = 46;
            this.rptContainer.TabIndex = 0;
            // 
            // txtTen_Nh_Vt
            // 
            this.txtTen_Nh_Vt.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTen_Nh_Vt.BackColor = System.Drawing.SystemColors.Control;
            this.txtTen_Nh_Vt.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_Nh_Vt.CheckTextSearched = false;
            this.txtTen_Nh_Vt.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_Nh_Vt.Enabled = false;
            this.txtTen_Nh_Vt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Nh_Vt.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_Nh_Vt.Location = new System.Drawing.Point(214, 6);
            this.txtTen_Nh_Vt.Name = "txtTen_Nh_Vt";
            this.txtTen_Nh_Vt.OldValue = null;
            this.txtTen_Nh_Vt.Size = new System.Drawing.Size(458, 13);
            this.txtTen_Nh_Vt.TabIndex = 7;
            this.txtTen_Nh_Vt.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtTen_Nh_Vt.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_Nh_Vt.Value = ((object)(resources.GetObject("txtTen_Nh_Vt.Value")));
            // 
            // txtMa_Nh_Vt
            // 
            this.txtMa_Nh_Vt.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Nh_Vt.CheckTextSearched = false;
            this.txtMa_Nh_Vt.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Nh_Vt.EmptyIsValid = true;
            this.txtMa_Nh_Vt.FieldDisplay = "Ten_Nh_Vt";
            this.txtMa_Nh_Vt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Nh_Vt.FoundIsValid = true;
            this.txtMa_Nh_Vt.Location = new System.Drawing.Point(108, 3);
            this.txtMa_Nh_Vt.MaxLength = 32;
            this.txtMa_Nh_Vt.Name = "txtMa_Nh_Vt";
            this.txtMa_Nh_Vt.OldValue = null;
            this.txtMa_Nh_Vt.Size = new System.Drawing.Size(100, 20);
            this.txtMa_Nh_Vt.TabIndex = 0;
            this.txtMa_Nh_Vt.TableName = "DMNHVT";
            this.txtMa_Nh_Vt.TextDisplay = this.txtTen_Nh_Vt;
            this.txtMa_Nh_Vt.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Nh_Vt.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Nh_Vt.Value = ((object)(resources.GetObject("txtMa_Nh_Vt.Value")));
            // 
            // lblMa_Nh_Vt
            // 
            this.lblMa_Nh_Vt.AutoSize = true;
            this.lblMa_Nh_Vt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_Nh_Vt.Location = new System.Drawing.Point(12, 6);
            this.lblMa_Nh_Vt.Name = "lblMa_Nh_Vt";
            this.lblMa_Nh_Vt.Size = new System.Drawing.Size(82, 14);
            this.lblMa_Nh_Vt.TabIndex = 87;
            this.lblMa_Nh_Vt.Text = "Nhóm hàng hoá";
            // 
            // txtCopies
            // 
            this.txtCopies.AllowNegative = false;
            this.txtCopies.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtCopies.Location = new System.Drawing.Point(108, 24);
            this.txtCopies.Name = "txtCopies";
            this.txtCopies.NumericValue = new decimal(new int[] {
            1,
            0,
            0,
            0});
            this.txtCopies.OldValue = null;
            this.txtCopies.Size = new System.Drawing.Size(100, 20);
            this.txtCopies.TabIndex = 1;
            this.txtCopies.Text = "1.00";
            this.txtCopies.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.txtCopies.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.IntNumber;
            this.txtCopies.Value = new decimal(new int[] {
            1,
            0,
            0,
            0});
            this.txtCopies.ZeroIsValid = false;
            // 
            // lblCopies
            // 
            this.lblCopies.AutoSize = true;
            this.lblCopies.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblCopies.Location = new System.Drawing.Point(12, 27);
            this.lblCopies.Name = "lblCopies";
            this.lblCopies.Size = new System.Drawing.Size(52, 14);
            this.lblCopies.TabIndex = 87;
            this.lblCopies.Text = "Số bản in";
            // 
            // FormDMVT02Viewer
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.CheckDetailMost = true;
            this.ClientSize = new System.Drawing.Size(794, 539);
            this.Name = "FormDMVT02Viewer";
            this.rptContainer.Panel1.ResumeLayout(false);
            this.rptContainer.Panel1.PerformLayout();
            this.rptContainer.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected override void OnGenerateColumns()
        {
            object[][] objArray = new object[5][];
            object[] objArray2 = new object[4];
            objArray2[0] = "Ma_Vt";
            objArray2[1] = "hàng hóa";
            objArray2[2] = "C";
            objArray[0] = objArray2;
            object[] objArray3 = new object[4];
            objArray3[0] = "Ten_Vt";
            objArray3[1] = "Tên hàng hóa";
            objArray3[2] = "C";
            objArray[1] = objArray3;
            object[] objArray4 = new object[4];
            objArray4[0] = "Dvt";
            objArray4[1] = "Đơn vị tính";
            objArray4[2] = "C";
            objArray[2] = objArray4;
            objArray[3] = new object[] { "Gia_Mua", "Giá mua", "N", AppInstance.TextNumericFormat.LocalPrice };
            objArray[4] = new object[] { "Gia_Ban", "Giá bán", "N", AppInstance.TextNumericFormat.LocalPrice };
            base.LocalColNames = objArray;
            base.OnGenerateColumns();
        }

        protected override void OnMakeReport()
        {
            base.LocalTable = new ReportDataAccess().DMVT02_Get(this.txtMa_Nh_Vt.Value);
            base.OnMakeReport();
        }

        protected override void OnPrint(bool pb_Printed)
        {
            if ((base.StimulReport != null) && (this.txtCopies.NumericValue >= 1M))
            {
                if (base.LocalTable != null)
                {
                    base.StimulReport.DataStore.Clear();
                    base.StimulReport.RegData(base.ReportFile, this.GetSelectedRows());
                    this.UpdateParameters();
                    this.OnSendParameters();
                }
                if (pb_Printed)
                {
                    base.StimulReport.Print();
                }
                else
                {
                    base.StimulReport.Show();
                }
            }
        }
    }
}

